package com.lening.common.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author 张蕊超
 * @datetime 2024/4/18 9:32
 * @description 时间工具包
 */
public class LocalDateUtil {
    public final static DateTimeFormatter DATE_FORMATTER_1 = DateTimeFormatter.ofPattern("yyyy-MM");
    public final static DateTimeFormatter DATE_FORMATTER_2 = DateTimeFormatter.ofPattern("yyyy年MM月");
    public final static DateTimeFormatter DATE_FORMATTER_3 = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
    public final static DateTimeFormatter DATE_FORMATTER_4 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public final static DateTimeFormatter DATE_FORMATTER_5 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    public final static DateTimeFormatter DATE_FORMATTER_6 = DateTimeFormatter.ofPattern("HH:mm:ss");
    public final static DateTimeFormatter DATE_FORMATTER_7 = DateTimeFormatter.ofPattern("yyyyMMdd");
    public final static DateTimeFormatter DATE_FORMATTER_8 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS");
    public final static DateTimeFormatter DATE_FORMATTER_9 = DateTimeFormatter.ofPattern("yyyy/MM/dd");

    /**
     * LocalDateTime -> String
     *
     * @param time
     * @return
     */
    public static String toString(LocalDateTime time) {
        if (time == null) {
            return null;
        }
        return time.format(DATE_FORMATTER_4);
    }
}
